home *** CD-ROM | disk | FTP | other *** search
- # SpecTcl, by S. A. Uhler
- # Copyright (c) 1994-1995 Sun Microsystems, Inc.
- #
- # See the file "license.txt" for information on usage and redistribution
- # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- #
- # do grid related stuff (take 2)
- # all of the information is derived from querying the table layout
- # Grid lines are placed in "odd" rows and columns
-
- # create the grid - for starting
- # master: master of the table
- # max rows/cols: how many grid lines to create
- # size: The thickness of each grid line
- # spacing: The grid spacing
- # color: The color of each grid line
-
- proc grid_create {master maxrows maxcols size color {relief raised}} {
- global P
- # undo_log create_grid $master $maxrows $maxcols
- dputs $master $maxrows,$maxcols
- # should use existing grid lines instead
- catch {frame $master.@0 -bg $color -bd 1 -relief $relief}
- blt_table $master $master.@0 1,1 -fill both
- for {set row 1} {$row <= $maxrows} {incr row 2} {
- grid_line $master row $color $size $relief $row
- }
- for {set col 1} {$col <= $maxcols} {incr col 2} {
- grid_line $master column $color $size $relief $col
- }
- grid_update $master
- resize_init $master [expr $maxrows/2-1] [expr $maxcols/2-1] $P(grid_spacing)
- grid_spacing $master
- blt_table row $master configure 0 -height 0 -resize none
- blt_table column $master configure 0 -width 0 -resize none
- }
-
- # create a grid row or column separator frame
- # master: master of the table
- # what: "row" or "column"
- # color: grid line color
- # thick: Grid line thickness
- # index: row or column number (must be odd). Defaults to end.
-
- proc grid_line {master what color thick {relief raised} {index ""}} {
- dputs "$master $what"
- if {$index == ""} { ;# find the next grid line
- set index 1
- set slaves [blt_table slaves $master $master.${what}@*]
- regexp {[^@]+@(.*)} [lindex $slaves 0] dummy index
- incr index 2
- } elseif {[winfo exists $master.${what}@$index]} {
- dputs skipping $index: already exists
- return $index
- }
- array set cursor {row sb_v_double_arrow column sb_h_double_arrow}
- array set option {row height column width}
- array set slot {row 0 column 1}
- set win $master.${what}@$index
- set place [join [lreplace {2 2} $slot($what) $slot($what) $index] ,]
-
- frame $win -bg $color -cursor $cursor($what) -bd 1 -relief $relief
- if {$what == "row"} {
- raise $win $master.row@1
- } else {
- lower $win $master.row@1
- }
- blt_table $master $win $place -fill both
- blt_table $what $master configure $index -$option($what) $thick
- bindtags $win "First grid $what [winfo toplevel $win] all"
- # too late - we've lost the row/column number
- # resize_insert $master $what $index
- return $index
- }
-
- # remove the last grid line - but not the first
-
- proc grid_remove {master what} {
- set slaves [blt_table slaves $master $master.${what}@*]
- if {[llength $slaves] > 2} {
- set slave [lindex $slaves 0]
- # puts "removing grid $what <$slave>"
- catch {destroy $slave}
- return 1
- } else {
- return 0
- }
- }
-
- # return current grid size
-
- proc grid_size {master {rows dummy} {cols dummy}} {
- upvar $rows maxrows $cols maxcols
- set maxrows [expr [llength [blt_table slaves $master $master.row@*]] * 2]
- set maxcols [expr [llength [blt_table slaves $master $master.column@*]] * 2]
- return $maxrows,$maxcols
- }
-
- # destroy a grid entirely
-
- proc grid_destroy {master} {
- set slaves [blt_table slaves $master $master.*@*]
- foreach i $slaves {
- destroy $i
- }
- }
-
- # see if we need to add a new grid row or column
- # what: row or column
- # return: # of grid lines we need to add
-
- proc grid_check {master what} {
- set slots [blt_table $what $master dimension]
- set grids [llength [blt_table slaves $master $master.${what}@*]]
- # puts "grid_check (1+$slots)/2 - $grids"
- return [expr (1+$slots)/2 - $grids] ;# CHECK
- }
-
- # update the row/col grid lengths after adding new grid lines to the table
- # look at the actual grid lines, as the table dimension isn't always reliable
- # master: The master of the table
-
- proc grid_update {master} {
- array set other {row column column row}
- set span 1
- foreach what {row column} {
- set slaves [blt_table slaves $master $master.$other($what)@*]
- regexp {[^@]+@(.*)} [lindex $slaves 0] dummy span
- incr span -1
- dputs $what $slaves span=$span
- foreach i [blt_table slaves $master $master.${what}@*] {
- blt_table configure $i -$other($what)span $span
- }
- }
- }
-
- # set the grid spacing to match the configuration info
- # master: Which table
-
- proc grid_spacing {master} {
- upvar #0 [winfo name $master] data
-
- dputs "$master $data(min_column) $data(min_row)"
- set column 0
- foreach width $data(min_column) {
- blt_table column $master configure [incr column 2] -width "$width Inf"
- }
- set row 0
- foreach height $data(min_row) {
- blt_table row $master configure [incr row 2] -height "$height Inf"
- }
- }
-
- # turn a grid on/off - specify its size
-
- proc grid_resize {win {size 3}} {
- if {$size == "on"} {set size 3}
- if {$size == "off"} {set size 0}
- set rows [blt_table row $win dimension]
- set cols [blt_table column $win dimension]
- for {set row 1} {$row < $rows} {incr row 2} {
- append row_list " $row"
- }
- for {set col 1} {$col < $cols} {incr col 2} {
- append col_list " $col"
- }
- blt_table column $win configure $col_list -width $size
- blt_table row $win configure $row_list -height $size
- }
-
- # insert a row or column into a grid - invoked from a grid-window binding
- # Then update the grid as needed
-
- proc grid_insert {win} {
- set what [split [winfo name $win] @]
- set master [winfo parent $win]
- set index [lindex $what 1]
- set what [lindex $what 0]
- dputs $what $master $index
- table_insert $master $what [incr index]
- # undo_mark
- grid_process $master $what 1
- update_table $master "insert $what $index"
- }
-
- # check the grid to see if it needs to be bigger
-
- proc grid_process {master what {always 0}} {
- global P Current
- if {$always || [grid_check $master $what]} {
- if {$what == "row"} {
- set color [$master.column@1 cget -bg]
- } else {
- set color [$master.row@1 cget -bg]
- }
- set relief [$master.row@1 cget -relief]
- set index [grid_line $master $what $color $P(grid_size) $relief]
- grid_update $master
- grid_spacing $master
- table_setup $master
- # need to have the new shape by here (we don't)
- arrow_create .can_$what $what $master
-
- # this is overkill!
- arrow_activate .can $Current(frame) ;# temporary?
-
- # undo_log create_slot $master $what $index
- return 1
- }
- return 0
- }
-
- # change the color of a grid (to make it invisible?)
-
- proc grid_color {master color} {
- if {[$master.row@1 cget -bg] == $color} {
- return 0
- }
- set list [info commands $master.*@*]
- foreach line $list {
- $line configure -bg $color
- }
- return 1
- }
-